//
// Created by francklinson on 2021/10/23 AT 10:19.
//
#include <iostream>
#include <chrono>
#include <thread>

//using namespace std;
/**
 * 结构体  利用其构造和析构函数 记录存在的时长
 */
struct Timer {
    std::chrono::time_point<std::chrono::steady_clock> start, end;
    std::chrono::duration<float> duration;

    Timer() {
        start = std::chrono::high_resolution_clock::now();
    }

    ~Timer() {
        end = std::chrono::high_resolution_clock::now();
        duration = end - start;
        float ms = duration.count() * 1000.0f;
        std::cout << "Timer took " << ms << "ms" << std::endl;
    }
};

void function() {
    Timer t;
    for (int i = 0; i < 100; ++i) {
        std::cout << "Hello!" << std::endl;
    }
}

int main() {
    function();
    std::cin.get();
    return 0;
}

